﻿namespace Bizspoke.BizTalk.Brma
{
    using System;
    using System.Web;

    [CLSCompliant(false)]
    public class SvcInstInfo
    {
        private string agentSrvID;
        private string appTypeName;
        internal uint ErrCode;
        internal string ErrMesg;
        private string groupName;
        private string instID;
        public string msgBoxDbName;
        public string msgBoxSrv;
        private string msgID;
        private string serviceClassID;

        public SvcInstInfo(string sGroupName, string sAppTypeName, string sInstID)
        {
            string str = this.DecodeFromUrl(sGroupName);
            string str2 = this.DecodeFromUrl(sAppTypeName);
            string str3 = this.DecodeFromUrl(sInstID);
            this.groupName = str;
            this.appTypeName = str2;
            this.InstID = str3;
            this.ErrCode = 0;
            this.ErrMesg = "";
            this.AgentSrvID = "";
            this.ServiceClassID = "";
        }

        public SvcInstInfo(string sGroupName, string sAppTypeName, string sInstID, string sServiceID, string sServiceClassID, string sMsgID, string sMsgBoxDbName, string sMsgBoxSrv)
        {
            this.groupName = sGroupName;
            this.appTypeName = sAppTypeName;
            this.msgBoxDbName = sMsgBoxDbName;
            this.msgBoxSrv = sMsgBoxSrv;
            this.InstID = sInstID;
            if (!this.InstID.StartsWith("{", StringComparison.Ordinal))
            {
                this.InstID = "{" + this.InstID + "}";
            }
            this.MsgID = sMsgID;
            if (!this.MsgID.StartsWith("{", StringComparison.Ordinal))
            {
                this.MsgID = "{" + this.MsgID + "}";
            }
            this.AgentSrvID = sServiceID;
            if (!this.AgentSrvID.StartsWith("{", StringComparison.Ordinal))
            {
                this.AgentSrvID = "{" + this.AgentSrvID + "}";
            }
            this.ServiceClassID = sServiceClassID;
            if (!this.ServiceClassID.StartsWith("{", StringComparison.Ordinal))
            {
                this.ServiceClassID = "{" + this.ServiceClassID + "}";
            }
            this.ErrCode = 0;
            this.ErrMesg = "";
        }

        private string DecodeFromUrl(string val)
        {
            return HttpUtility.UrlDecode(val);
        }

        private string EncodeForUrl(string val)
        {
            return HttpUtility.UrlEncodeUnicode(val);
        }

        internal void SetError(uint ErrorCode, string ErrorMesg)
        {
            this.ErrCode = ErrorCode;
            this.ErrMesg = ErrorMesg;
        }

        public string AgentSrvID
        {
            get
            {
                return this.agentSrvID;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    new Guid(value);
                }
                this.agentSrvID = value;
            }
        }

        public string AppTypeName
        {
            get
            {
                return this.appTypeName;
            }
            set
            {
                this.appTypeName = value;
            }
        }

        public uint ErrorCode
        {
            get
            {
                return this.ErrCode;
            }
        }

        public string ErrorMesg
        {
            get
            {
                return this.ErrMesg;
            }
        }

        public bool FullyQualifiedInstance
        {
            get
            {
                bool flag = false;
                bool flag2 = false;
                if (this.AppTypeName.Trim().Length > 0)
                {
                    flag = true;
                }
                if (((this.InstID.Trim().Length > 0) && (this.AgentSrvID.Trim().Length > 0)) && (this.ServiceClassID.Trim().Length > 0))
                {
                    flag2 = true;
                }
                return (flag && flag2);
            }
        }

        internal string GroupBy
        {
            get
            {
                return ("HostName=\"" + this.AppTypeName + "\"");
            }
        }

        public string GroupName
        {
            get
            {
                return this.groupName;
            }
            set
            {
                this.groupName = value;
            }
        }

        public string InstID
        {
            get
            {
                return this.instID;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    new Guid(value);
                }
                this.instID = value;
            }
        }

        public string MsgBoxDbName
        {
            get
            {
                return this.msgBoxDbName;
            }
            set
            {
                this.msgBoxDbName = value;
            }
        }

        public string MsgBoxSrv
        {
            get
            {
                return this.msgBoxSrv;
            }
            set
            {
                this.msgBoxSrv = value;
            }
        }

        public string MsgID
        {
            get
            {
                return this.msgID;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    new Guid(value);
                }
                this.msgID = value;
            }
        }

        public string ServiceClassID
        {
            get
            {
                return this.serviceClassID;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    new Guid(value);
                }
                this.serviceClassID = value;
            }
        }
    }
}

